import base64
from flask import url_for
from models import Img, User


def to_img(img_binary, mime_type="image/jpeg"):
    base64_str = base64.b64encode(img_binary).decode("utf-8")
    return f"data:{mime_type};base64,{base64_str}"

#TODO

# def img_default():
#     return [url_for('static', filename='default.jpg')]
#
# def get_img_by_url(uid,url):
#     img = Img.query.filter_by(uid=uid,url=url).order_by(Img.time.desc()).all()
#     if not img or not img.image:
#         return img_default()
#     return [to_img(img.image)]
#
# def get_intro_img_by_user_id(uid):
#
#
# def save_intro_img